#include <iostream>
#include "userview_impl.h"
#include "tools.h"
#include <getch.h>
using namespace std;

UserViewImpl::UserViewImpl()
{
	service = new UserServiceImpl;
}

void UserViewImpl::Menu()
{
	while(1)
	{
		system("clear");
		cout << "*********欢迎来到用户系统*******" << endl;
		cout << "        1、显示用户信息" << endl;
		cout << "        2、书籍查找" << endl;
		cout << "        3、书籍预约" << endl;
		cout << "        4、书籍推荐" << endl;
		cout << "        5、退出" << endl;
		cout << "*********************************" << endl;
		char cmd = 0;
		while(1)
		{
			cmd = getch();
			if(cmd >='1' && cmd <='5')
				break;
		}
		cout << cmd << endl;
		switch(cmd-'0')
		{
			case 1:Reader();break;
			case 2:Search();break;
			case 3:Order();break;
			case 4:Recommend();break;
			case 5:return;
			
		}
 	}
}
void UserViewImpl::Reader()
{
	int id;
	cout << "请输入要查询用户的ID号：" << endl;
	cin >> id;
	service->ReaderSearch(id);
	anykey_continue();
}
void UserViewImpl::Search()
{
	char name[20];
	cout << "请输入要查询书籍相关名称：" << endl;
	cin >> name;
	service->BookSearch(name);
	anykey_continue();
}
void UserViewImpl::Order()
{
	int r_id;
	int b_id;
	cout << "请输入预约用户ID号：" << endl;
	cin >> r_id;
	cout << "请输入要预约书籍ID号：" << endl;
	cin >> b_id;
	if(service->BookOrder(r_id,b_id))
	{
		cout << "预约成功！！" << endl;
	}
	else
	{
		cout << "预约失败！！" << endl;
	}
	anykey_continue();
}
void UserViewImpl::Recommend()
{
    service->Recommend();
    
}
UserViewImpl::~UserViewImpl()
{
	delete service;
}
